import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:yp/config/config.dart';
import 'package:yp/helper.dart';
import 'package:yp/router.dart';
import 'package:yp/services/api.dart';
import 'package:yp/widgets/select_button.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:multi_image_picker/multi_image_picker.dart';
import 'package:flutter_native_image/flutter_native_image.dart';
import 'package:image_picker/image_picker.dart';
import 'package:get/get.dart' hide MultipartFile hide FormData;
import 'logic.dart';
import 'state.dart';
import 'package:dio/dio.dart';

class AftersaleApplyPage extends StatefulWidget {
  AftersaleApplyPage({Key key}) : super(key: key);

  @override
  _AftersaleApplyPage createState() {
    return _AftersaleApplyPage();
  }
}

class _AftersaleApplyPage extends State<AftersaleApplyPage> {
  final AftersaleApplyLogic logic = Get.put(AftersaleApplyLogic());
  final AftersaleApplyState state = Get.find<AftersaleApplyLogic>().state;

  List<Asset> images = [];
  List newImg = [];

  Future<void> loadAssets(index) async {
    if (images == null) {
      images = List<Asset>();
    }
    if (index == 2) {
      var imagesList = [];
      try {
        imagesList = await MultiImagePicker.pickImages(
          maxImages: 1,
          enableCamera: false,
          cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
          materialOptions: MaterialOptions(
            actionBarColor: "#FCCD00",
            actionBarTitle: "选择图片",
            allViewTitle: "所有图片",
            useDetailsView: false,
            selectCircleStrokeColor: "#000000",
          ),
        );
        if (imagesList.length != 0) {
          images = imagesList;

          Navigator.of(Get.context).pop();
        }
      } on Exception catch (e) {
        Navigator.of(Get.context).pop();
      }
      if (imagesList.length == 0) return;
      for (Asset asset in images) {
        ByteData byteData = await asset.getByteData();
        List<int> imageData = byteData.buffer.asUint8List();
        MultipartFile multipartFile = MultipartFile.fromBytes(
          imageData,
          filename: asset.name,
        );
        Api.upImage(
          FormData.fromMap({
            "file": multipartFile,
          }),
        ).listen((event) {
          if (event["code"] == 0) {
            state.fileList.add(event["result"][0]["url"]);
            newImg.add(event["result"][0]["url"]);
            logic.update();
          }
        });
      }
    } else {
      try {
        final ImagePicker _picker = ImagePicker();
        var img = await _picker.pickImage(source: ImageSource.camera);
        var _image;
        var data;
        var imageData;
        if (Platform.isAndroid) {
          _image = File(img.path).path;
          var compressedFile = await FlutterNativeImage.compressImage(
            _image,
            quality: 10,
          );
          imageData = await compressedFile.readAsBytes();
        } else {
          _image = File(img.path).path;
          var compressedFile = await FlutterNativeImage.compressImage(
            _image,
            quality: 10,
          );
          data = await rootBundle.load(compressedFile.path);
          imageData = data.buffer.asUint8List();
        }
        Navigator.of(Get.context).pop();
        EasyLoading.show();
        MultipartFile multipartFile = MultipartFile.fromBytes(
          imageData,
          filename: 'a.jpg',
        );
        Api.upImage(
          FormData.fromMap({
            "file": multipartFile,
          }),
        ).listen((event) {
          if (event["code"] == 0) {
            state.fileList.add(event["result"][0]["url"]);
            newImg.add(event["result"][0]["url"]);
            logic.update();
            EasyLoading.dismiss();
          } else {
            EasyLoading.dismiss();
          }
        });
      } on Exception catch (e) {
        Navigator.of(Get.context).pop();
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(color: Colors.black),
        title: Text(
          '申请售后',
          style: TextStyle(
            color: Colors.black,
            fontSize: 32.sp,
          ),
        ),
        centerTitle: true,
        elevation: 0,
      ),
      body: GetBuilder<AftersaleApplyLogic>(
        builder: (logic) {
          double Cheight = double.parse("${90 * state.datelis.length}");
          return SingleChildScrollView(
            child: state.detail != null
                ? Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        height: Cheight,
                        child: ListView.builder(
                            itemCount: state.datelis.length,
                            physics: NeverScrollableScrollPhysics(),
                            itemBuilder: (date, i) {
                              var data = state.datelis[i];
                              // state.num = state.datelis[i]['qty'].toInt();
                              // state.maxnum = state.datelis[i]['qty'].toInt();
                              return Container(
                                height: 90,
                                color: Colors.white,
                                margin: EdgeInsets.only(top: 3.w),
                                padding: EdgeInsets.symmetric(
                                    vertical: 20.w, horizontal: 20.w),
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    GestureDetector(
                                      onTap: () {},
                                      child: Container(
                                        padding: EdgeInsets.only(right: 20.w),
                                        // child: state.maxnum != 0
                                        //     ? Image.asset(
                                        //   state.maxnum != 0
                                        //             ? "assets/images/selectIcon1.png"
                                        //             : "assets/images/select1.png",
                                        //         width: 32.w,
                                        //       )
                                        //     : Image.asset(
                                        //         "assets/images/disno.png",
                                        //         width: 32.w,
                                        //       ),
                                        child: Image.asset(
                                          "assets/images/selectIcon1.png",
                                          width: 32.w,
                                        ),
                                      ),
                                    ),
                                    Container(
                                        width: 176.w,
                                        padding: EdgeInsets.only(right: 16.w),
                                        child: Stack(
                                          children: [
                                            Image.network(
                                              data['item_picture'],
                                              width: 160.w,
                                              height: 160.w,
                                              fit: BoxFit.cover,
                                            ),
                                          ],
                                        )),
                                    Expanded(
                                      child: Column(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        mainAxisAlignment: MainAxisAlignment.start,
                                        children: [
                                          Row(
                                            children: [
                                              if (data['pmt_sign'] == 1)
                                                Container(
                                                  margin:
                                                      EdgeInsets.only(top: 1, right: 6),
                                                  padding:
                                                      EdgeInsets.fromLTRB(8, 3, 8, 3),
                                                  decoration: new BoxDecoration(
                                                      border: new Border.all(
                                                          color: Color(0xFFFF0000),
                                                          width: 0.5),
                                                      color: Colors.red,
                                                      borderRadius:
                                                          new BorderRadius.circular(
                                                              (9.0))),
                                                  alignment: Alignment.center,
                                                  child: Text(
                                                    '赠品',
                                                    style: TextStyle(
                                                      fontSize: 18.sp,
                                                      color: Color(0xffffffff),
                                                    ),
                                                    maxLines: 1,
                                                    overflow: TextOverflow.ellipsis,
                                                  ),
                                                ),
                                              Expanded(
                                                child: Text(
                                                  data['item_name'],
                                                  style: TextStyle(
                                                    color: Color(0xff333333),
                                                    fontSize: 28.w,
                                                  ),
                                                  maxLines: 1,
                                                  textAlign: TextAlign.start,
                                                  overflow: TextOverflow.ellipsis,
                                                ),
                                              ),
                                            ],
                                          ),
                                          SizedBox(
                                            height: 40.w,
                                          ),
                                          Container(
                                            width: 500.w,
                                            child: Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.spaceBetween,
                                              crossAxisAlignment: CrossAxisAlignment.end,
                                              children: [
                                                RichText(
                                                  text: TextSpan(
                                                    children: [
                                                      TextSpan(
                                                        text: '￥',
                                                        style: TextStyle(
                                                            color: Config.mainColor,
                                                            fontSize: 24.w),
                                                      ),
                                                      TextSpan(
                                                        text: state.detail != null
                                                            ? "${data['trade_price']}"
                                                            : '',
                                                        style: TextStyle(
                                                            color: Config.mainColor,
                                                            fontSize: 30.w),
                                                      ),
                                                    ],
                                                  ),
                                                ),
                                                if (state.maxnum != 0)
                                                  Container(
                                                    child: data['pmt_sign'] == 1
                                                        ? Text(
                                                            "x ${data['remain_cancel_qty']}",
                                                            style: TextStyle(
                                                              fontSize: 28.w,
                                                              color: Color(0xff333333),
                                                            ),
                                                          )
                                                        : Row(
                                                            children: [
                                                              GestureDetector(
                                                                onTap: () {
                                                                  if (state.isPre == 1 &&
                                                                          state.detail[
                                                                                      "amount"]
                                                                                  [
                                                                                  "deposit_amount"] !=
                                                                              0.0 /*
                                                                      && state.detail["amount"]["need_pay_amount"] != 0.0*/
                                                                      ) {
                                                                    toast("此订单不支持部分退款");
                                                                    return;
                                                                  }
                                                                  logic.reduce(i);
                                                                },
                                                                child: Image(
                                                                  image: AssetImage(
                                                                      "assets/images/reduce.png"),
                                                                  width: 40.w,
                                                                ),
                                                              ),
                                                              SizedBox(
                                                                width: 10.w,
                                                              ),
                                                              Text(
                                                                state.isPre != 1
                                                                    ? "${state.num}"
                                                                    : "${state.datelis[i]["num"]}",
                                                                style: TextStyle(
                                                                  fontSize: 28.w,
                                                                  color:
                                                                      Color(0xff333333),
                                                                ),
                                                              ),
                                                              SizedBox(
                                                                width: 10.w,
                                                              ),
                                                              GestureDetector(
                                                                onTap: () {
                                                                  if (state.isPre == 1 &&
                                                                          state.detail[
                                                                                      "amount"]
                                                                                  [
                                                                                  "deposit_amount"] !=
                                                                              0.0 /*
                                                                      && state.detail["amount"]["need_pay_amount"] != 0.0*/
                                                                      ) {
                                                                    toast("此订单不支持部分退款");
                                                                    return;
                                                                  }
                                                                  logic.add(i);
                                                                },
                                                                child: Image(
                                                                  image: AssetImage(
                                                                      "assets/images/plus.png"),
                                                                  width: 40.w,
                                                                ),
                                                              ),
                                                            ],
                                                          ),
                                                  ),
                                              ],
                                            ),
                                          ),
                                          if (state.maxnum != 0 && data['pmt_sign'] != 1)
                                            Expanded(
                                              child: Row(
                                                mainAxisAlignment: MainAxisAlignment.end,
                                                children: [
                                                  RichText(
                                                    text: TextSpan(
                                                      children: [
                                                        TextSpan(
                                                          text: '最高可申请',
                                                          style: TextStyle(
                                                              color: Color(0xff888888),
                                                              fontSize: 20.w),
                                                        ),
                                                        TextSpan(
                                                          // text:"${state.maxnum}",
                                                          text: state.isPre != 1
                                                              ? "${state.maxnum}"
                                                              : "${state.datelis[i]['max_num'].toInt()}",
                                                          style: TextStyle(
                                                              color: Color(0xffFF0808),
                                                              fontSize: 20.w),
                                                        ),
                                                        TextSpan(
                                                          text: "件",
                                                          style: TextStyle(
                                                              color: Color(0xff888888),
                                                              fontSize: 20.w),
                                                        ),
                                                      ],
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              );
                            }),
                      ),
                      if (state.detail['af_service_flag'] == 1)
                        Container(
                          color: Colors.white,
                          margin: EdgeInsets.only(top: 20.w),
                          padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 20.w),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  Text(
                                    '*',
                                    style: TextStyle(
                                      color: Color(0xffF3405D),
                                      fontSize: 28.w,
                                    ),
                                  ),
                                  Text(
                                    '退货方式',
                                    style: TextStyle(
                                      color: Color(0xff666666),
                                      fontSize: 28.w,
                                    ),
                                  ),
                                ],
                              ),
                              SizedBox(
                                height: 15.w,
                              ),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: [
                                  SelectButton(
                                    title: "仅退款",
                                    isSelected: state.type == 1,
                                    onTap: () => logic.setType(1),
                                  ),
                                  SizedBox(width: 20.w),
                                  if (state.detail['is_service_order'] != 1)
                                    SelectButton(
                                      title: "退货退款",
                                      isSelected: state.type == 2,
                                      onTap: () => logic.setType(2),
                                    ),
                                ],
                              )
                              // Row(
                              //   mainAxisAlignment: MainAxisAlignment.start,
                              //   children: [
                              //     SelectButton(
                              //       title: "仅退款",
                              //       isSelected: state.type == 1,
                              //       onTap: () => logic.setType(1),
                              //     ),
                              //   ],
                              // )
                            ],
                          ),
                        ),
                      InkWell(
                        onTap: () {
                          if (state.maxnum != 0) {
                            showBottomSheet(context);
                          }
                        },
                        child: Container(
                          color: Colors.white,
                          margin: EdgeInsets.only(top: 3.w),
                          padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 20.w),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Row(
                                    children: [
                                      Text(
                                        '*',
                                        style: TextStyle(
                                          color: Color(0xffF3405D),
                                          fontSize: 28.w,
                                        ),
                                      ),
                                      Text(
                                        '售后原因',
                                        style: TextStyle(
                                          color: Color(0xff666666),
                                          fontSize: 28.w,
                                        ),
                                      ),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      Text(
                                        state.remark != "" ? state.remark : '请选择',
                                        style: TextStyle(
                                          color: state.remark != ""
                                              ? Color(0xff000000)
                                              : Color(0xff999999),
                                          fontSize: 28.w,
                                        ),
                                      ),
                                      SizedBox(
                                        width: 10.w,
                                      ),
                                      Image.asset(
                                        "assets/images/more.png",
                                        width: 32.w,
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ),
                      Container(
                        color: Colors.white,
                        margin: EdgeInsets.only(top: 3.w),
                        padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 20.w),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Row(
                              children: [
                                Text(
                                  '问题描述',
                                  style: TextStyle(
                                    color: Color(0xff666666),
                                    fontSize: 28.w,
                                  ),
                                ),
                              ],
                            ),
                            Container(
                              color: Colors.white,
                              child: Column(
                                children: [
                                  Container(
                                    height: 150.w,
                                    child: TextField(
                                      enabled: state.maxnum != 0 ? true : false,
                                      maxLines: 4,
                                      // minLines: 1,
                                      // maxLength: 5,
                                      controller: state.controller,
                                      textAlignVertical: TextAlignVertical.center,
                                      inputFormatters: <TextInputFormatter>[
                                        LengthLimitingTextInputFormatter(400) //限制长度
                                      ],
                                      decoration: InputDecoration(
                                        isDense: true,
                                        contentPadding: EdgeInsets.all(0),
                                        prefixIconConstraints: BoxConstraints(
                                          maxWidth: 70.w,
                                          minWidth: 70.w,
                                        ),
                                        hintText: '您可以在这里详细地描述商品的问题（400字）',
                                        hintStyle: TextStyle(
                                          fontSize: 24.sp,
                                          color: Color(0xff999999),
                                        ),
                                        border: InputBorder.none,
                                      ),
                                    ),
                                  ),

                                  /// 上传图片
                                  Container(
                                      width: 750.w,
                                      margin: EdgeInsets.only(
                                        top: 20.w,
                                      ),
                                      child: Wrap(
                                        children: imageListFun(this.newImg),
                                      )
                                      // Wrap(
                                      //
                                      //   children: [
                                      //     Container(
                                      //         child: Stack(
                                      //           children: [
                                      //             Padding(
                                      //               padding: EdgeInsets.all(15.w),
                                      //               child: Image.asset(
                                      //                 "assets/images/avatar.png",
                                      //                 width: 100.w,
                                      //                 height: 100.w,
                                      //               ),
                                      //             ),
                                      //             Positioned(
                                      //               top: 2.w,
                                      //               right: 2.w,
                                      //               child: ClipOval(
                                      //                 child: Container(
                                      //                   color: Color(0xff000000),
                                      //                   child: Image.asset(
                                      //                     "assets/images/guanbi.png",
                                      //                     width: 30.w,
                                      //                     height: 30.w,
                                      //                   ),
                                      //                 ),
                                      //               ),
                                      //             )
                                      //           ],
                                      //         )),
                                      //     Container(
                                      //       margin: EdgeInsets.only(
                                      //         left: 10.w,
                                      //       ),
                                      //       child: Padding(
                                      //         padding: EdgeInsets.all(10.w),
                                      //         child: InkWell(
                                      //           onTap: () {
                                      //             selectImage(context);
                                      //           },
                                      //           child: Image.asset(
                                      //             "assets/images/upload.png",
                                      //             width: 100.w,
                                      //             height: 100.w,
                                      //           ),
                                      //         ),
                                      //       ),
                                      //     ),
                                      //   ],
                                      // ),
                                      ),
                                ],
                              ),
                            ),
                            GestureDetector(
                              onTap: () {
                                if (state.maxnum != 0) {
                                  logic.submitApply();
                                }
                              },
                              child: Container(
                                width: 750.w,
                                height: 80.w,
                                margin: EdgeInsets.only(
                                  top: 40.w,
                                ),
                                decoration: BoxDecoration(
                                  color: state.maxnum != 0
                                      ? Config.mainColor
                                      : Color(0xff999999),
                                  borderRadius: BorderRadius.circular(40.w),
                                ),
                                child: Center(
                                  child: Text(
                                    "提交申请",
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 28.w,
                                    ),
                                  ),
                                ),
                              ),
                            )
                          ],
                        ),
                      ),
                    ],
                  )
                : Container(),
          );
        },
      ),
    );
  }

  List<Widget> imageListFun(List images) {
    Widget addimg = Container(
      child: GetBuilder<AftersaleApplyLogic>(
        builder: (logic) {
          return Container(
            child: GestureDetector(
              onTap: () {
                if (state.maxnum != 0) {
                  selectImage(Get.context);
                }
              },
              child: Container(
                color: Color(0xfff4f4f4),
                width: 200.w,
                height: 200.w,
                child: Center(
                  child: Icon(
                    Icons.add,
                    color: Color(0xffBEBEBE),
                  ),
                ),
              ),
            ),
          );
        },
      ),
    );
    // uploada
    var list2 = newImg
        .asMap()
        .map((index, item) {
          Widget widget = Image.network('${item}', width: 200, height: 200);
          return MapEntry(index, _createGridViewItem(widget, index));
        })
        .values
        .toList();

    List<Widget> list = List<Widget>.from(list2);

    if (list.length < 9) {
      list.add(addimg);
    }
    return list;
  }

  //图片展示
  _createGridViewItem(widget, index) {
    return Container(
      height: 200.w,
      width: 200.w,
      color: Color(0xff999999),
      margin: EdgeInsets.only(right: 20.w, bottom: 20.w),
      child: Stack(
        children: [
          widget,
          Positioned(
            top: 0,
            right: 0,
            child: GestureDetector(
              onTap: () {
                setState(() {
                  newImg.removeAt(index);
                  state.fileList.removeAt(index);
                });
              },
              child: Icon(
                Icons.close,
                color: Colors.grey,
              ),
            ),
          )
        ],
      ),
    );
  }

  //照片选择
  void selectImage(BuildContext context) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
        builder: (BuildContext context) {
          //构建弹框中的内容
          return Container(
            height: 300.w,
            child: Column(
              children: [
                Container(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      InkWell(
                        onTap: () {
                          loadAssets(1);
                        },
                        child: Container(
                          height: 90.w,
                          width: 750.w,
                          decoration: BoxDecoration(
                            border: Border(
                              bottom: BorderSide(
                                color: Color(0xffeeeeee),
                                width: 1.w,
                              ),
                            ),
                          ),
                          child: Center(
                            child: Text(
                              "拍摄",
                              style: TextStyle(
                                // color: Color(0xff2222),
                                color: Colors.black,
                                fontSize: 32.sp,
                              ),
                              textAlign: TextAlign.center,
                            ),
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () {
                          loadAssets(2);
                        },
                        child: Container(
                          height: 90.w,
                          width: 750.w,
                          child: Center(
                            child: Text(
                              "从手机相册选择",
                              style: TextStyle(
                                // color: Color(0xff2222),
                                color: Colors.black,
                                fontSize: 32.sp,
                              ),
                              textAlign: TextAlign.center,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  color: Color(0xffF2F3F4),
                  height: 20.w,
                ),
                Expanded(
                  child: InkWell(
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                    child: Container(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Container(
                            height: 90.w,
                            width: 750.w,
                            child: Center(
                              child: Text(
                                "取消",
                                style: TextStyle(
                                  // color: Color(0xff2222),
                                  color: Colors.black,
                                  fontSize: 32.sp,
                                ),
                                textAlign: TextAlign.center,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                )
              ],
            ),
          );
        },
        context: context);
  }

  ///显示底部弹框的功能
  void showBottomSheet(BuildContext context) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      builder: (BuildContext context) {
        //构建弹框中的内容
        return SingleChildScrollView(
          child: Container(
            padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(
                Radius.circular(25.w),
              ),
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Color(0xFFEA5504).withOpacity(.149),
                  offset: Offset(0, 0), //阴影y轴偏移量
                  blurRadius: 1,
                  spreadRadius: .3,
                )
              ],
            ),
            child: Column(
              children: [
                Padding(
                  padding: EdgeInsets.symmetric(
                    vertical: 36.w,
                    horizontal: 30.w,
                  ),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          GestureDetector(
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                            child: Text(
                              "",
                              style: TextStyle(
                                color: Color(0xff999999),
                                fontSize: 28.sp,
                              ),
                            ),
                          ),
                          Text(
                            "取消原因",
                            style: TextStyle(
                              color: Color(0xff666666),
                              fontSize: 28.sp,
                            ),
                          ),
                          GestureDetector(
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                            child: Image.asset(
                              "assets/images/close2.png",
                              width: 44.w,
                            ),
                          ),
                        ],
                      ),
                      GetBuilder<AftersaleApplyLogic>(
                        builder: (logic) {
                          return Container(
                            height: 600.w,
                            child: Container(
                              margin: EdgeInsets.only(
                                top: 20.w,
                              ),
                              padding: EdgeInsets.symmetric(
                                horizontal: 20.w,
                              ),
                              child: ListView.builder(
                                shrinkWrap: true,
                                itemBuilder: (ctx, i) {
                                  var item = state.classList[i];
                                  return InkWell(
                                    onTap: () {
                                      logic.select(i);
                                    },
                                    child: Container(
                                      padding: EdgeInsets.symmetric(vertical: 25.w),
                                      decoration: BoxDecoration(
                                          border: Border(
                                              bottom:
                                                  BorderSide(color: Color(0xffefefef)))),
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.start,
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: [
                                          Expanded(
                                            child: Text(
                                              item['type_name'] ?? '1111',
                                              style: TextStyle(
                                                color: Color(0xff222222),
                                                fontSize: 24.sp,
                                              ),
                                              maxLines: 2,
                                              textAlign: TextAlign.start,
                                              overflow: TextOverflow.ellipsis,
                                            ),
                                          ),
                                          item['selected']
                                              ? Image(
                                                  image: AssetImage(
                                                      "assets/images/selectIcon1.png"),
                                                  width: 36.w,
                                                )
                                              : Image(
                                                  image: AssetImage(
                                                      "assets/images/save.png"),
                                                  width: 36.w,
                                                ),
                                        ],
                                      ),
                                    ),
                                  );
                                },
                                itemCount: state.classList.length,
                              ),
                            ),
                          );
                        },
                      ),
                      SimpleDialogOption(
                        child: Container(
                          color: Colors.white,
                          child: GetBuilder<AftersaleApplyLogic>(
                            builder: (logic) {
                              return GestureDetector(
                                onTap: () {
                                  logic.submit();
                                  Navigator.of(context).pop();
                                },
                                child: Container(
                                  width: 750.w,
                                  height: 80.w,
                                  decoration: BoxDecoration(
                                    color: Config.mainColor,
                                    borderRadius: BorderRadius.circular(40.w),
                                  ),
                                  child: Center(
                                    child: Text(
                                      "提交",
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 28.w,
                                      ),
                                    ),
                                  ),
                                ),
                              );
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      },
      context: context,
    );
  }
}
